package com.tanhua.api.db;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.domain.db.BlackList;
import com.tanhua.domain.db.UserInfo;
import com.tanhua.mapper.BlackListMapper;
import com.tanhua.mapper.UserInfoMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class BlackListApiImpl implements BlackListApi {

    @Autowired
    private BlackListMapper blackListMapper;

    @Autowired  //因为返回的数据是多表封装后的UserInfo数据 所以在userInfoMapper中定义多表查询语句
    private UserInfoMapper userInfoMapper;

    //分页查询
    public IPage<UserInfo> findPage(Long userId, Integer page, Integer pagesize) {

        //组装分页数据
        Page pages = new Page(page,pagesize);
        //分页查询
        IPage<UserInfo> pb=userInfoMapper.findPage(pages,userId);

        return pb;
    }

    @Override
    public void deleteById(Long userId, Long blackId) {
        QueryWrapper<BlackList> qw = new QueryWrapper<BlackList>();
        qw.eq("user_id",userId);
        qw.eq("black_user_id",blackId);
        blackListMapper.delete(qw);
    }
}
